<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

	public function index()
	{
		$data['title'] = 'Bootstrap bro';
		$this->load->view('template/header', $data);
		$this->load->view('template/navbar');
		$this->load->view('home');
		$this->load->view('template/footer');
	}

	public function sidebar(){
		$this->data['title'] = 'sidebar bro';
		$this->load->view('template/header');
		$this->load->view('sidebar');
		$this->load->view('template/footer');
	}

	public function post(){
		$this->data['title'] = 'sidebar bro';
		$this->load->view('template/header');

	  $this->load->model('mpost');
	  $data['isi'] = $this->mpost->ambil_data();
	  $this->load->view('post',$data);
  		$this->load->view('template/footer');
 }

	public function login(){
		$post = $this->input->post('submit');
		if($post){

			$this->load->model('account');

			$this->account->set_user($this->input->post('usr'));
			$this->account->set_password($this->input->post('pwd'));

			$this->form_validation->set_rules('usr', 'Username', 'required');
			$this->form_validation->set_rules('pwd', 'Password', 'required');

			if ($this->form_validation->run() == FALSE)	{
				$data['error'] = validation_errors();		
			}else{	
				if($this->account->do_login()){
					header('location: '.site_url().'/dashboard');
				}else{
					$data['error'] = 'User dan Password tidak sesuai,<br />silahkan periksa kembali';
				}
			}	
		}else{
			$data['error']   = $this->session->flashdata('error');			
		}		
		$this->load->view('login', $data);
	}
}

